package vh.sphynx.runtime.util;

import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class LogUtil {
	
	private static Logger logger = org.apache.log4j.LogManager.getLogger(LogUtil.class);
		
	public void configure(Map<Object, Object> config) {
		Properties p = new Properties();
		for(Object key: config.keySet())
			p.put(key.toString(), config.get(key));
		PropertyConfigurator.configure(p);
	}
	
	public void log(int severity, String message, Object...args) {
		if (args.length > 0)
			message = String.format(message, args);
		Level level = null;
		switch(severity) {
		case 0:
			level = Level.INFO;
			break;
		case 1:
			level = Level.WARN;
			break;
		case 2:
			level = Level.ERROR;
			break;
		default:
			level = Level.INFO; 	
		}
		logger.log(level, message);
	}
}
